package com.dhy.controller;

import com.dhy.beans.ClassscheduleClasssplit;
import com.dhy.msg.AjaxResponse;
import com.dhy.service.ClassscheduleClasssplitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.dhy.utils.DateUtils.*;


import java.util.Date;
import java.util.List;

//查询空教室
@Api(tags = "空教室查询API获取")
@RestController
@RequestMapping("/search")
public class FilterEmptyCourse
{
    @Resource
    private ClassscheduleClasssplitService classscheduleClasssplitService;

    @ApiOperation("查询当前日期有哪些教室是空闲的")
    @GetMapping("/emptyByDate")
    @Cacheable("CourseByDate")//@ApiParam("查询日期")
    public AjaxResponse getEmptyClassRoomByDate( @ApiParam("日期,格式yyyy-MM-dd")@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                        HttpServletRequest request, HttpServletResponse response)
    {
        int week = calculateTermWeek(date);
        int weekDay = calculateTermWeekDay(date);
        List<ClassscheduleClasssplit> courseByRequire = classscheduleClasssplitService.getCourseByRequire(String.valueOf(week), String.valueOf(weekDay), null, null);
        return AjaxResponse.success(courseByRequire);
    }

    @ApiOperation("根据条件查询空教室")
    @GetMapping("/emptyByExample")
    @Cacheable(value = "courseByExample")
    public AjaxResponse getEmptyClassRoomByExample(
            @ApiParam("周次")@RequestParam(required = false) String week
    ,@ApiParam("星期")@RequestParam(required = false) String day,
     @ApiParam("节次")@RequestParam(required = false)String section
     ,@ApiParam("楼栋")@RequestParam(required = false)String building
    ,HttpServletRequest httpServletRequest)
    {
        List<ClassscheduleClasssplit> courseByRequire = classscheduleClasssplitService.getCourseByRequire(week, day, section,building);
        return AjaxResponse.success(courseByRequire);
    }
}
